from sgmllib import SGMLParser
import urllib
import win32com.client

thunder = win32com.client.Dispatch('ThunderAgent.Agent.1')


class URLLister(SGMLParser):
    def reset(self):                             
        SGMLParser.reset(self)
        self.urls = []
    def start_a(self, attrs):
        href = [v for k, v in attrs if k=='thunderhref']
        if href:
            self.urls.extend(href)

start = 49810
beg = 0
end = 12

for i in range(beg, end):
    print start + i - beg
    usock = urllib.urlopen("http://www.pingshu8.com/down_%d.html" % (start + i - beg) )
    parser = URLLister()
    parser.feed(usock.read())
    usock.close()
    parser.close()
    for url in parser.urls:
        thunder.AddTask(url)
print 'commit'
thunder.CommitTasks()
